/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/


import request from '@/utils/request';
import { IAntdTablePageParams, IPromiseApi, IPromiseListApi } from '@/types/type';
import { AntdFormUtils } from 'ahooks/es/useAntdTable/types';
import {
  ICategoryItem,
  ISceneAuditDetail,
  ISceneAuditList,
  ISceneAuditListParams,
  IScenesRecordParams,
  IScenesTestReleaseParams,
} from '@/types/sceneAudit';
import base from './base';
import { paginationParams } from '@/utils/soa/utils';

export async function getSceneAuditList(
  { current, pageSize }: IAntdTablePageParams,
  formData: AntdFormUtils,
) {
  const {
    data
  } = await request.get<IPromiseListApi<ISceneAuditList>>(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/scenesRecord/page`,
    {
      params: {
        ...paginationParams(current, pageSize),
        ...formData,
      },
    },
  );
  return {
    list: data?.itemSize ? data?.dataList : [],
    total: data?.pageCount,
  };
}

// 场景发布履历详情接口
export async function sceneAuditDetail(sceneRecordUuid: string) {
  return await request.get<IPromiseApi<ISceneAuditDetail>>(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/scenesRecord`,
    {
      params: {
        sceneRecordUuid,
      },
    },
  );
}

// 场景发布履历审核接口
export async function scenesAudit(data: ISceneAuditListParams, sceneRecordUuid: string) {
  return await request.post(`/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/scenes/audit`, {
    data: {
      ...data,
      sceneRecordUuid,
    },
  });
}

// 场景履历分类修改
export async function scenesRecordEdit(data: IScenesRecordParams, sceneRecordUuid: string) {
  return await request.put(`/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/scenesRecord`, {
    data: {
      ...data,
      sceneRecordUuid,
    },
  });
}

//场景分类
export async function scenesRecord(params: { seriesCode: string }) {
  return await request.get<IPromiseApi<ICategoryItem[]>>(
    `/${base.API}/ms-soa-scene/${base.VERSION}/category`,
    {
      params
    },
  );
}

// 所有车辆VIN查询
export async function getVehicleVinList() {
  return await request.get(`/${base.API}/ms-soa-vehicle/${base.VERSION}/admin/vehicle`);
}

export async function scenesTestRelease(data: IScenesTestReleaseParams) {
  return await request.post(`/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/scenes/do_test`, {
    data: {
      ...data,
    },
  });
}
